package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.domain.HomeRecommendProduct;
import com.itheima.manager.SmsHomeRecommendProductManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class SmsHomeRecommendProductController {

    @Autowired
    SmsHomeRecommendProductManager smsHomeRecommendProductManager;


    //分页查询
    @GetMapping("/home/recommendProduct/list")
    public R findByPage(@RequestParam(defaultValue = "1",required = false)Integer pageNum,
                        @RequestParam(defaultValue = "10",required = false)Integer pageSize,
                        @RequestParam(required = false)String productName,
                        @RequestParam(required = false)Integer recommendStatus)
    {
        return smsHomeRecommendProductManager.findByPage(pageNum,pageSize,productName,recommendStatus);

    }

    //添加首页推荐
    @PostMapping("/home/recommendProduct/create")
    public R addNew(@RequestBody HomeRecommendProduct homeRecommendProduct)
    {
        return smsHomeRecommendProductManager.addNew(homeRecommendProduct);
    }


    //批量删除
    @PostMapping("/home/recommendProduct/delete")
    public R delete(Integer [] ids)
    {
        return smsHomeRecommendProductManager.delete(ids);
    }

    //批量修改推荐状态
    @PostMapping("/home/recommendProduct/update/recommendStatus")
    public R update(Integer [] ids,Integer recommendStatus)
    {
        return smsHomeRecommendProductManager.update(ids,recommendStatus);
    }

    //修改排序
    @PostMapping("/home/recommendProduct/update/sort/{id}")
    public R sort(@PathVariable Integer id,@RequestParam(required = false)Integer sort)
    {
        return smsHomeRecommendProductManager.sort(id,sort);
    }
}
